package cn.it.shop.dao.impl;

import java.util.Set;

import org.hibernate.classic.Session;
import org.springframework.stereotype.Repository;

import cn.it.shop.dao.RoleDao;
import cn.it.shop.pojo.Role;

@Repository("roleDao")
public class RoleDaoImpl extends BaseDaoImpl<Role> implements
		RoleDao {
	// 通过角色ID查询,角色信息,级联抓去权限信息
	public Role getFetchPid(int id) {
		String hql = "FROM Role r LEFT JOIN FETCH r.privilegeSet WHERE r.id=:id";
		Session session = sessionFactory.getCurrentSession();
		return (Role) session.createQuery(hql) //
				.setInteger("id", id)//
				.uniqueResult();
	}

	@Override
	public void updateOnlyRole(Role role) {
		String hql = "UPDATE Role r SET r.name=:name,r.detail=:detail WHERE r.id=:id";
		Session session = sessionFactory.getCurrentSession();
		session.createQuery(hql)//
				.setString("name", role.getName())//
				.setString("detail", role.getDetail())//
				.setInteger("id", role.getId())//
				.executeUpdate();
	}
}
